<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>设置间隔日期，来获取某些日期可选</title>
    <link rel="stylesheet" type="text/css" href="../../style/public.css">
    <link rel="stylesheet" type="text/css" href="../../libraries/jquery-ui/jquery-ui.min.css">
</head>
<body>
    <div id="section">
        <p>设置间隔日期，来获取某些日期可选</p>
        <p><input type="text" id="date"></p>
    </div>
	
</body>
    <script src="../../libraries/jquery-1.11.1.min.js"></script>
    <script src="../../libraries/jquery-ui/jquery-ui.min.js"></script>
    
    <script>
    $(function(){

        var natDays = [];
        var dataCount = function(n,t,d,m,y){
            /*
            n:间隔月数
            t:间隔天数
            d:日
            m:月
            y:年
            */
            if (n <= 0) {
                return 1;
            }else{
                var returnDate = function(t,d,m,y){
                    var _date = new Date();
                    var _y = y || _date.getFullYear(); //年
                    var _m = m || _date.getMonth()+1; //月
                    var _d = d || _date.getDate(); //日
                    var _dMax = new Date(_y, _m, 0).getDate(); //当月最大天数
                    if (_d > _dMax) { //日期大于当月最大天数
                        _d = _d - _dMax ;
                        _m += 1;
                        if (_m > 12) {
                            _m = 1;
                            _y += 1;
                        };
                        return dataCount(n-1,t,_d,_m,_y);
                    }else{
                        natDays.push([_y,_m,_d]);
                        var _d =  _d + t;
                        return arguments.callee(t,_d,_m,_y);
                    }
                }(t,d,m,y)
            }
        } 
        dataCount(4,5) //计算3个月，间隔5天的日期

        
        function nationalDays(date) {  
            for (i = 0; i < natDays.length; i++) {  
                if (date.getFullYear() == natDays[i][0] && date.getMonth() == natDays[i][1] - 1  
                && date.getDate() == natDays[i][2]) {  
                    return [true, natDays[i][0] + '_day'];  
                }  
            }  
            return [false, ''];  
        } 
        $('#date').datepicker({
            minDate: new Date(),
            maxDate: '+3M',
            beforeShowDay: nationalDays
        });
    })    
    </script>
</html>